package com.bianguo.android.functiondemo.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bianguo.android.functiondemo.R;
import com.bianguo.android.functiondemo.utils.MLog;

import java.util.ArrayList;

import butterknife.BindView;

public class MainAdapter extends BaseRecyclerAdapter<String> {

    public MainAdapter(Context mContext, ArrayList<String> list) {
        super(mContext, list);
    }

    @Override
    public BaseViewHolder createHolder(@NonNull ViewGroup viewGroup, int viewType) {
        View view = inflater.inflate(R.layout.item_main_layout, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void bindHolder(@NonNull BaseViewHolder baseViewHolder, int position) {
        final ViewHolder viewHolder = (ViewHolder) baseViewHolder;
        String s = list.get(position);
        viewHolder.contentTv.setText(s);
        viewHolder.deleteTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onClickItemListener != null) {
                    onClickItemListener.onClickItemListener(MainAdapter.this, view, viewHolder.getAdapterPosition());
                }
            }
        });
        viewHolder.itemContentLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onClickItemListener != null) {
                    onClickItemListener.onClickItemListener(MainAdapter.this, view, viewHolder.getAdapterPosition());
                }
            }
        });
    }

    public static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.item_main_content)
        TextView contentTv;
        @BindView(R.id.item_main_layout)
        LinearLayout itemLayout;
        @BindView(R.id.item_main_delete)
        TextView deleteTv;
        @BindView(R.id.item_main_content_layout)
        CardView itemContentLayout;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
